package web.suzy.oj.controller.admin;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.entity.problem.Tag;
import web.suzy.oj.pojo.entity.problem.TagClassification;
import web.suzy.oj.service.admin.tag.AdminTagService;

import javax.annotation.Resource;
import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: AdminTagController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/28 14:32
 */
@RestController
@RequestMapping("/api/admin/tag")
public class AdminTagController {
    @Resource
    private AdminTagService adminTagService;

    /**
     * 方法名: addTag
     * 描述: 添加题目标签
     *
     * @param tag 标签
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.entity.problem.Tag>
     * @date 2022/11/28 14:33
     * @auther YangSuzy
     **/
    @PostMapping("")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Tag> addTag(@RequestBody Tag tag) {
        return adminTagService.addTag(tag);
    }

    /**
     * 方法名: updateTag
     * 描述: 更新题目标签
     *
     * @param tag 标签
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/28 14:39
     * @auther YangSuzy
     **/
    @PutMapping("")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Void> updateTag(@RequestBody Tag tag) {
        return adminTagService.updateTag(tag);
    }

    /**
     * 方法名: deleteTag
     * 描述: 删除题目标签
     *
     * @param tid 标签ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/28 14:43
     * @auther YangSuzy
     **/
    @DeleteMapping("")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Void> deleteTag(@RequestParam("tid") Long tid) {
        return adminTagService.deleteTag(tid);
    }

    /**
     * 方法名: getTagClassification
     * 描述: 获取标签分类
     *
     * @return web.suzy.oj.common.result.ResultBean<java.util.List < web.suzy.oj.pojo.entity.problem.TagClassification>>
     * @date 2022/11/29 12:20
     * @auther YangSuzy
     **/
    @GetMapping("/classification")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<List<TagClassification>> getTagClassification() {
        return adminTagService.getTagClassification();
    }

    /**
     * 方法名: addTagClassification
     * 描述: 添加标签分类
     *
     * @param tagClassification 标签分类
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.entity.problem.TagClassification>
     * @date 2022/11/29 13:15
     * @auther YangSuzy
     **/
    @PostMapping("/classification")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<TagClassification> addTagClassification(
            @RequestBody TagClassification tagClassification) {
        return adminTagService.addTagClassification(tagClassification);
    }

    /**
     * 方法名: updateTagClassification
     * 描述: 更新标签分类
     *
     * @param tagClassification 标签分类
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/29 13:18
     * @auther YangSuzy
     **/
    @PutMapping("/classification")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Void> updateTagClassification(@RequestBody TagClassification tagClassification) {
        return adminTagService.updateTagClassification(tagClassification);
    }

    /**
     * 方法名: deleteTagClassification
     * 描述: 删除标签分类
     *
     * @param tcid 标签分类ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/29 13:21
     * @auther YangSuzy
     **/
    @DeleteMapping("/classification")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Void> deleteTagClassification(@RequestParam("tcid") Long tcid) {
        return adminTagService.deleteTagClassification(tcid);
    }
}
